<?php

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use App\Models\Component;
use App\Models\ComponentTypeCode;
use App\Models\ComponentType;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        User::factory(10)->create();

        User::findOrFail(1)->update([
            'name' => 'Admin',
            'email' => 'admin@admin.com',
            'is_admin' => true
        ]);

        $categories = [
            [
                'name' => 'header',
                'slug' => 'header',
                'description' => 'header'
            ],
            [
                'name' => 'footer',
                'slug' => 'footer',
                'description' => 'footer'
            ]
        ];

        DB::table('categories')->insert($categories);
        Component::factory(100)->create();
        foreach (Component::all() as $component) {
            $component->categories()->attach([1, 2]);
            $codeTypes = ['html', 'react', 'vue'];
            foreach ($codeTypes as $codeType) {
                $componentType = ComponentType::create([
                    'component_id' => $component->id,
                    'name' => $codeType,
                    'description' => 'this is the description'
                ]);

                if($codeType === 'html') {
                    $codeTypes = ['html', 'css', 'js'];
                    foreach ($codeTypes as $codeType) {
                        ComponentTypeCode::create([
                            'component_type_id' => $componentType->id,
                            'name' => $codeType,
                            'code' => '<p class="bg-orange-500 text-white">hello world</p>'
                        ]);
                    }
                }

                if($codeType === 'react') {
                    ComponentTypeCode::create([
                        'component_type_id' => $componentType->id,
                        'name' => "JSX",
                        'code' => '<p class="bg-orange-500 text-white">react component</p>'
                    ]);
                }

                if($codeType === 'vue') {
                    ComponentTypeCode::create([
                        'component_type_id' => $componentType->id,
                        'name' => "Vue Component",
                        'code' => '<p class="bg-orange-500 text-white">vue js</p>'
                    ]);
                }
            }
        }
    }
}
